﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CCH.DAO;
using CCH.Lib;

public partial class _70_7002 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ((MasterPage)this.Master).Create_menu(7002);
        if (!this.IsPostBack)
        {
            //this.ObjectDataSource1.SelectParameters["cla_sfuno"].DefaultValue = this.DropDownList1.SelectedValue;
            this.GridView1.DataBind();
            
        }

        //判斷來自JS 使用_doPostBack(updatePanel,"") 的情況
        if (Request["__EVENTTARGET"] == this.UpdatePanel1.ClientID && String.IsNullOrEmpty(Request["__EVENTARGUMENT"]))
        {
            this.ObjectDataSource1.SelectParameters["cla_sfuno"].DefaultValue = this.DropDownList1.SelectedValue;
            this.GridView1.DataBind();
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int rowIndex = System.Convert.ToInt32(e.CommandArgument);
        int id = System.Convert.ToInt32(this.GridView1.DataKeys[rowIndex].Value.ToString());

        //停用
        if (e.CommandName.Equals("disable"))
        {
            int mes_rowcount = new messageDAO().Get_message_AllData_Count(id);
            int you_rowcount = new youtubeDAO().Get_youtube_AllData_Count(id);
            int res_rowcount = new researchDAO().Get_research_AllData_Count(id);

            if (mes_rowcount > 0 || you_rowcount > 0 || res_rowcount > 0)
            {
                JsUtil.AlertJs(this, "此分類項目使用中無法刪除!");
            }
            else
            {
                new classificationDAO().Delete_classification(id, new SessionObject().SessionUserID);
                this.GridView1.DataBind();
                JsUtil.AlertJs(this, "刪除成功!");
            }
            
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //JsUtil.AlertJs(this, "shit"); 
        this.ObjectDataSource1.SelectParameters["cla_sfuno"].DefaultValue = this.DropDownList1.SelectedValue;
        this.GridView1.DataBind();
    }

    protected String Get_peopleName(object peo_uid)
    {
        int uid = Convert.ToInt32(peo_uid);

        return new peopleDAO().Get_peopleName(uid);
    }

    protected String Get_DateTime(object datetime)
    {
        return ((DateTime)datetime).ConvertToROCDT();
    }

    protected String Get_url_new()
    {
        return string.Format("7002-1.aspx?mode=new&sfuno={0}&modal=true&TB_iframe=true&width=800", this.DropDownList1.SelectedItem.Value);
    }

    protected String Get_url(object cla_no)
    {
        return string.Format("7002-1.aspx?mode=edit&ID={0}&modal=true&TB_iframe=true&width=800", cla_no.ToString());
    }

    protected String Get_FunctionName(object cla_sfuno)
    {
        int sfuno = Convert.ToInt32(cla_sfuno);

        string sfuname="";
        switch (sfuno){
            case 2001:
                sfuname = "最新消息";
                break;
            case 3001:
                sfuname = "研究論文";
                break;
            case 3002:
                sfuname = "醫學新知";
                break;
            case 5001:
                sfuname = "活動訊息";
                break;
            case 5003:
                sfuname = "衛教文章";
                break;
            case 5004:
                sfuname = "衛教影片";
                break;
            default:
                sfuname = "";
                break;
        }
        return sfuname;
    }
}